//
// Created by Zhangwj on 2023/9/27.
//

#include <stdexcept>
#include "PrimaryExpNode.h"

std::unique_ptr<PrimaryExpNode> PrimaryExpNode::PrimaryExpParser(Parser &parser) {
    //PrimaryExp → '(' Exp ')' | LVal | Number
    std::unique_ptr<PrimaryExpNode> primaryExpNode = std::make_unique<PrimaryExpNode>();
    if (parser.getLexType(0) == LexType::LPARENT) {
        parser.next();
        primaryExpNode->Exp = ExpNode::ExpParser(parser);
        if (parser.getLexType(0) == LexType::RPARENT) {
            parser.next();
        }
    } else if (parser.getLexType(0) == LexType::INTCON) {
        primaryExpNode->Number = NumberNode::NumberParser(parser);
    } else {
        primaryExpNode->LVal = LValNode::LValParser(parser);
    }
    return primaryExpNode;
}
